package com.rumor.background.Utils.Admin;

import com.github.pagehelper.PageInfo;
import com.rumor.background.Mapper.AdminMapper;
import com.rumor.background.Utils.Page.PageUtils;
import com.rumor.background.Utils.Utils;
import com.rumor.background.pojo.*;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

public class AdminUtils {

    public static Object getPageResultForRumor(HttpServletRequest request, List<RumorContributeBackground> rcb) throws IOException {
        for(RumorContributeBackground r: rcb){
            String[] link = Utils.getImgListLink(request, "RUMOR/" + r.getImg_location());
            r.setImgLink(link);
        }
        return PageUtils.getPageResult(new PageInfo<RumorContributeBackground>(rcb));
    }

    public static Object getPageResultForFound(HttpServletRequest request, List<FoundBackground> fd) throws IOException {
        for(FoundBackground f: fd){
            String[] link = Utils.getImgListLink(request, "FOUND/" + f.getImg_location());
            f.setImgLink(link);
        }
        return PageUtils.getPageResult(new PageInfo<FoundBackground>(fd));
    }

    public static Object getPageResultForLost(HttpServletRequest request, List<LostBackground> ls) throws IOException {
        for(LostBackground l: ls){
            String[] link = Utils.getImgListLink(request, "LOST/" + l.getImg_location());
            l.setImgLink(link);
        }
        return PageUtils.getPageResult(new PageInfo<LostBackground>(ls));
    }



    public static boolean checkLoginType(HttpServletRequest request, AdminMapper ram){
        String username = request.getParameter("username");
        String admin_code = request.getParameter("admin_code");
        return !admin_code.equals(ram.queryAdminCodeByUsername(username));
    }


}
